$(() => {
  userInfo();
  function userInfo() {
    $.ajax({
      url: '/my/userinfo',
      success(res) {
        form.val('form', res.data);
      },
    });
  }
  $('.layui-form').submit(function (e) {
    e.preventDefault();
    let info = $(this).serializeArray();
    info.push({ name: 'id', value: localStorage.getItem('id') });
    $.ajax({
      type: 'POST',
      url: '/my/userinfo',
      data: info,
      success(res) {
        layer.msg(res.message);
        if (res.status === 0) {
          userInfo();
          window.parent.getUserInfo();
        }
      },
    });
  });
  $('.layui-form')[0].onreset = function (e) {
    e.preventDefault();
    userInfo();
  };
});
